var o = getApp();

Page({
    data: {},
    onLoad: function(o) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        wxfaceapp.postMsg({
            targetAppid: o.data.accept_message_id,
            content: JSON.stringify({
                bolshow: !1,
                moneyBol: !0
            }),
            success: function(o) {},
            fail: function(o) {}
        });
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getUserProfileTap: function() {
        var o = this;
        wx.getUserProfile({
            desc: "获取用户信息",
            success: function(e) {
                console.log("info:", e);
                var n = {
                    nickName: e.userInfo.nickName,
                    avatarUrl: e.userInfo.avatarUrl,
                    gender: e.userInfo.gender
                };
                o.loginbtn(n);
            }
        });
    },
    loginbtn: function(o) {
        wx.showLoading({
            title: "登录中"
        }), setTimeout(function() {
            wx.hideLoading();
        }, 3e3);
        var e = this;
        wxfaceapp.isLoginOnFaceApp({
            success: function() {
                e.setLoginState(o);
            },
            fail: function(o) {
                wx.showToast({
                    title: o.reply,
                    icon: "none",
                    duration: 2e3
                }), console.log(o, "登录失败");
            }
        });
    },
    setLoginState: function(e) {
        var n = this;
        wx.login({
            success: function(t) {
                console.log("login登录成功，获取用户info"), t.code ? n.requestServerData(o.getFrogproNetAddresss("member.login.index"), "get", {
                    code: t.code,
                    info: e
                }).then(function(e) {
                    var n = e.data;
                    if (1 == n.result) {
                        n.data.user_info && wx.setStorageSync("nickname", n.data.user_info.nickname), n.msg.session && wx.setStorageSync("session", n.msg.session), 
                        n.msg.wx_token && wx.setStorageSync("wx_token", n.msg.wx_token), n.data.store && wx.setStorageSync("storeMessage", n.data.store);
                        var t = {
                            wx_token: n.msg.wx_token,
                            session: n.msg.session,
                            store_id: n.data.store.store_id,
                            dispatch_type_id: 2,
                            goods_id: n.data.store.goods_id,
                            host: o.data.host,
                            uniacid: o.data.uniacid
                        };
                        console.log("kkkk:::", t), wxfaceapp.postMsg({
                            targetAppid: o.data.accept_message_id,
                            content: JSON.stringify(t),
                            success: function(o) {},
                            fail: function(o) {
                                wx.showToast({
                                    title: o.reply,
                                    icon: "none",
                                    duration: 2e3
                                }), console.log(o, "发送失败");
                            }
                        }), wx.hideLoading(), wx.redirectTo({
                            url: "/packageC/frogpro/storeManagement/storeManagement"
                        });
                    } else wx.showToast({
                        title: n.msg,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    }), console.log("错误信息:::" + e.errMsg);
                }).catch(function(o) {
                    console.log("错误信息:::" + o.errMsg);
                }) : console.log("错误信息:::" + res.errMsg);
            },
            fail: function(o) {
                console.log("登录失败，请求被拒绝！获取用户登录态失败！" + o);
            }
        });
    },
    requestServerData: function(o, e, n) {
        return new Promise(function(t, s) {
            wx.request({
                url: o,
                data: n,
                header: {
                    "Content-Type": "application/json",
                    Accept: "application/json"
                },
                method: e,
                success: function(o) {
                    t(o);
                },
                fail: function(o) {
                    s(o);
                }
            });
        });
    }
});